﻿using P2P.Client.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace P2P.Client
{
    public class R<T>
    {
        public int Code { get; set; }
        public string Msg { get; set; }
        public T Data { get; set; }

        public static R<T> Ok()
        {
            return new R<T> { Code = (int)StatusCode.SUCCESS, Data = default };
        }

        public static R<T> Ok(T data)
        {
            return new R<T> { Code = (int)StatusCode.SUCCESS, Data = data };
        }

        public static R<T> Ok(T data, string msg)
        {
            return new R<T> { Code = (int)StatusCode.SUCCESS, Data = data, Msg = msg };
        }

        public static R<T> Failed()
        {
            return new R<T> { Code = (int)StatusCode.FAIL, Data = default };
        }

        public static R<T> Failed(int code)
        {
            return new R<T> { Code = code, Data = default };
        }

        public static R<T> Failed(string msg)
        {
            return new R<T> { Code = (int)StatusCode.FAIL, Data = default, Msg = msg };
        }

        public static R<T> Failed(T data)
        {
            return new R<T> { Code = (int)StatusCode.FAIL, Data = data };
        }

        public static R<T> Failed(T data, string msg)
        {
            return new R<T> { Code = (int)StatusCode.FAIL, Data = data, Msg = msg };
        }
    }
}
